//
//  RecommendCollectionViewCell.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "RecommendCollectionViewCell.h"
#import "FitHeader.h"
#import "S1mpl3HotListenViewController.h"
#import "Model.h"

#import "TwoToOne.h"
#import "Discovery.h"
#import "S1mpl3Recommend.h"
#import "S1mpl3Focus.h"
#import "S1mpl3Special.h"
#import "S1mpl3SpecialCollectionViewCell.h"
#import "S1mpl3TelevisionCollectionViewCell.h"
#import "S1mpl3DiscoveryCollectionViewCell.h"
#import "S1mpl3ClassifyCollectionViewCell.h"
#import "S1mpl3FocusCollectionViewCell.h"
#import "S1mpl3MoreRecommendViewController.h"
#import "ZBBListenNewsViewController.h"
#import "S1mpl3AlbumViewController.h"
#import "S1mpl3WebViewViewController.h"
#import "S1mpl3SpecialHotViewController.h"
#import "LZPlayViewController.h"
#import "UIImage+GIF.h"

@interface RecommendCollectionViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,ScroDelegate>

@end

@implementation RecommendCollectionViewCell

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

-(void)changeColor{
    self.backgroundColor = [Model shareInstance].ViewColor;
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatView];

        [self changeColor];
        
        
    }
    return self;
}

-(void)creatView{
    [self getData];
    UICollectionViewFlowLayout *contentFlowlayout = [[UICollectionViewFlowLayout alloc] init];
    //    contentFlowlayout.itemSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height);
    //    contentFlowlayout.itemSize = CGSizeMake(375, 300);
    contentFlowlayout.minimumInteritemSpacing = 0;
    contentFlowlayout.minimumLineSpacing = 0;
    contentFlowlayout.sectionInset = UIEdgeInsetsMake(0, 0, 10 * FITHeight, 0);
    contentFlowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    _recommendCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 375 * FITWidth, 617 * FITHeight - 64 - 49) collectionViewLayout:contentFlowlayout];
    _recommendCollectionView.dataSource = self;
    _recommendCollectionView.delegate = self;
    _recommendCollectionView.showsVerticalScrollIndicator = NO;
    _recommendCollectionView.backgroundColor = [UIColor colorWithRed:0.93 green:0.92 blue:0.91 alpha:1];
    [self.contentView addSubview:_recommendCollectionView];
    
    //努力加载中
    self.progressView = [[MBProgressHUD alloc]initWithView:self.contentView];
    [[[_progressView subviews]firstObject] removeFromSuperview];
    [[[_progressView subviews] objectAtIndex:1] removeFromSuperview];
    [_progressView setMode:0];
    [_progressView show:YES];
    NSString  *name = @"RED.gif";
    _progressView.color = [UIColor clearColor];
    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(-70 * FITWidth, -80 * FITHeight, 140 * FITWidth, 100 * FITHeight)];
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 10;
    imageView.opaque = NO;
    
    [[[[[_progressView subviews] lastObject] subviews] firstObject] removeFromSuperview];
    
    imageView.image = [UIImage sd_animatedGIFWithData:imageData];
    [[[_progressView subviews] lastObject] addSubview:imageView];    [self.contentView addSubview:_progressView];
    
    
    
    //推荐注册
    [_recommendCollectionView registerClass:[S1mpl3TelevisionCollectionViewCell class] forCellWithReuseIdentifier:@"recommendIdentifier"];
    //精品听单注册
    [_recommendCollectionView registerClass:[S1mpl3SpecialCollectionViewCell class] forCellWithReuseIdentifier:@"specialIdentifier"];
    //发现新奇单注册
    [_recommendCollectionView registerClass:[S1mpl3DiscoveryCollectionViewCell class] forCellWithReuseIdentifier:@"discoveryIdentifier"];
    //更多分类注册
    [_recommendCollectionView registerClass:[S1mpl3ClassifyCollectionViewCell class] forCellWithReuseIdentifier:@"classifyIdentifier"];
    //视图注册
    [_recommendCollectionView registerClass:[S1mpl3FocusCollectionViewCell class] forCellWithReuseIdentifier:@"focusIdentifier"];
    
    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head0"];
    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head1"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head2"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head3"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head4"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head5"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head6"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head7"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head8"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head9"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head10"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head11"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head12"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head13"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head14"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head15"];

    [_recommendCollectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head16"];
  
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
}

#pragma mark --collectionView代理方法

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 17;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        S1mpl3FocusCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"focusIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.delegate = self;
        if (_focusDataSourceArray.count != 0) {
            cell.dataSourceArray = _focusDataSourceArray;
        }
        return cell;
    }else if (indexPath.section == 1) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [_recommendDataSourceArray objectAtIndex:indexPath.row];
        
        return cell;
    }else if (indexPath.section == 2) {
        S1mpl3SpecialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"specialIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.special = [_specialDataSourceArray objectAtIndex:indexPath.row];
        return cell;
    }else if (indexPath.section == 3) {
        S1mpl3DiscoveryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"discoveryIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.discovery = [_discoveryDataSourceArray objectAtIndex:indexPath.row];
        return cell;
    }else if (indexPath.section == 4) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听新闻"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 5) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听小说"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 6) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听脱口秀"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 7) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听相声"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 8) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听音乐"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 9) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听情感心声"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 10) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听历史"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 11) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听讲座"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 12) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听广播剧"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 13) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听儿童故事"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 14) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听外语"] objectAtIndex: indexPath.row];
        return cell;
    }else if (indexPath.section == 15) {
        S1mpl3TelevisionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        cell.recommend = [[_hotRecommendDataSourceDictionary objectForKey:@"听游戏"] objectAtIndex: indexPath.row];
        return cell;
    }else {
        S1mpl3ClassifyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"classifyIdentifier" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return _recommendDataSourceArray.count;
            break;
        case 2:
            return _specialDataSourceArray.count;
            break;
        case 3:
            return _discoveryDataSourceArray.count;
            break;
        case 4:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听新闻"]count];
            break;
        case 5:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听小说"]count];
            break;
        case 6:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听脱口秀"]count];
            break;
        case 7:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听相声"]count];
            break;
        case 8:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听音乐"]count];
            break;
        case 9:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听情感心声"]count];
            break;
        case 10:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听历史"]count];
            break;
        case 11:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听讲座"]count];
            break;
        case 12:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听广播剧"]count];
            break;
        case 13:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听儿童故事"]count];
            break;
        case 14:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听外语"]count];
            break;
        case 15:
            return [[_hotRecommendDataSourceDictionary objectForKey:@"听游戏"]count];
            break;
        case 16:
            return 1;
            break;
        default:
            break;
    }
    
    return 0;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 16) {
        return CGSizeMake(0, 0);
    }
    return CGSizeMake(375 * FITWidth, 40 * FITHeight);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        if (_recommendDataSourceArray.count != 0) {
            
            S1mpl3AlbumViewController *albumVC = [[S1mpl3AlbumViewController alloc] init];
            albumVC.albumId = [[_recommendDataSourceArray objectAtIndex:indexPath.row] albumId];
            albumVC.myTitle = [[_recommendDataSourceArray objectAtIndex:indexPath.row] title];
            [self.s1mpl3Nav pushViewController:albumVC animated:YES];

        }
    }else if (indexPath.section == 2){
        if (_specialDataSourceArray.count != 0) {
            S1mpl3HotListenViewController *s1mpl3HotListenVC = [[S1mpl3HotListenViewController alloc] init];
            S1mpl3SpecialHot *s1 = [_specialDataSourceArray objectAtIndex:indexPath.row];
            //NSLog(@"%@", s1);
            //    NSLog(@"%@", [NSString stringWithFormat:@"%@", [[[_dataSourceDic objectForKey:_sectionArray[indexPath.section]] objectAtIndex:indexPath.row] specialID]]);
            //NSLog(@"%ld", indexPath.row);
            s1mpl3HotListenVC.specialID = s1.specialId;
            s1mpl3HotListenVC.contentType = s1.contentType;
            [self.s1mpl3Nav pushViewController:s1mpl3HotListenVC animated:YES];
        }
    }else if (indexPath.section == 16){
        [self.moreDelegate MoreJumpDelegate];
    }
     else 
     {
        S1mpl3AlbumViewController *s1vc = [[S1mpl3AlbumViewController alloc]init];
        s1vc.albumId = [[_hotRecommendDataSourceDictionary objectForKey:_hotRecommendArray[indexPath.section - 4]][indexPath.row] albumId];
        [self.s1mpl3Nav pushViewController:s1vc animated:YES];
              }
}

-(void)tapAction:(UITapGestureRecognizer *)tap{
    HeadView *view = (HeadView *)tap.view;
    
    switch (view.tag) {
        case 1000:{
            S1mpl3MoreRecommendViewController *moreRecommend = [[S1mpl3MoreRecommendViewController alloc] init];
            [self.s1mpl3Nav pushViewController:moreRecommend animated:YES];
        }
            break;
            
            default:
            break;
    }

    if ([view.leftLabel.text isEqualToString:@"精品听单"]) {
        S1mpl3SpecialHotViewController *s1mpl3SpecialHotVC = [[S1mpl3SpecialHotViewController alloc] init];
        [self.s1mpl3Nav pushViewController:s1mpl3SpecialHotVC animated:YES];
    }
    
    if (![view.leftLabel.text isEqualToString:@"小编推荐"] && ![view.leftLabel.text isEqualToString:@"精品听单"]) {
        
            ZBBListenNewsViewController *listen = [[ZBBListenNewsViewController alloc]init];
            listen.categoryId =  [_hotRecommendListenDic objectForKey:view.leftLabel.text];
            [self.s1mpl3Nav pushViewController:listen animated:YES];
        
    }
    
    
    


    /*
    ZBBListenNewsViewController *listen = [[ZBBListenNewsViewController alloc]init];
    listen.categoryId =  [_hotRecommendListenDic objectForKey:view.leftLabel.text];
    [self.s1mpl3Nav pushViewController:listen animated:YES];
     */

  }

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    
   //HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
    UICollectionReusableView *view1 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head1" forIndexPath:indexPath];
    [view1 removeFromSuperview];
   // [view removeFromSuperview];
    
    
    
        switch (indexPath.section) {
            case 0:
            {UICollectionReusableView *view1 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head0" forIndexPath:indexPath];

            view1.frame = CGRectMake(0, 0, 0, 0);
            return view1;
            }
        case 1:{
            
            HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head1" forIndexPath:indexPath];

            view.leftLabel.text = @"小编推荐";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            view.rightLabel.text = @"更多";
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            view.tag = 1000;
            
            return view;
        }
            break;
        case 2:
            {
            HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head2"forIndexPath:indexPath];
            view.leftLabel.text = @"精品听单";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            view.tag = 1001;
            return view;
        }
            break;
        case 3:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head3" forIndexPath:indexPath];

            view.leftLabel.text = @"发现新奇";
           view.rightLabel.text = @"";
            view.moreImageView.image = [UIImage imageNamed:@""];
//            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
//            [view.rightLabel addGestureRecognizer:tap];
//           view.rightLabel.tag = 1002;
            return view;
        }
            break;
        case 4:
        {
            HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head4" forIndexPath:indexPath];

        view.leftLabel.text = @"听新闻";
        view.rightLabel.text = @"更多";
        view.moreImageView.image = [UIImage imageNamed:@"更多"];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 5:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head5" forIndexPath:indexPath];

            view.leftLabel.text = @"听小说";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            
            return view;
        }
            break;
        case 6:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head6" forIndexPath:indexPath];

            view.leftLabel.text = @"听脱口秀";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 7:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head7" forIndexPath:indexPath];

            view.leftLabel.text = @"听相声";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 8:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head8" forIndexPath:indexPath];

            view.leftLabel.text = @"听音乐";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 9:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head9" forIndexPath:indexPath];

           view.leftLabel.text = @"听情感心声";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 10:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head10" forIndexPath:indexPath];

            view.leftLabel.text = @"听历史";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 11:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head11" forIndexPath:indexPath];

            view.leftLabel.text = @"听讲座";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 12:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head12" forIndexPath:indexPath];

            view.leftLabel.text = @"听广播剧";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 13:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head13" forIndexPath:indexPath];

            view.leftLabel.text = @"听儿童故事";
            view.rightLabel.text = @"更多";
            view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 14:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head14" forIndexPath:indexPath];

            view.leftLabel.text = @"听外语";
            view.rightLabel.text = @"更多";
             view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [ view addGestureRecognizer:tap];
            
            return  view;
        }
            break;
        case 15:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head15" forIndexPath:indexPath];

            view.leftLabel.text = @"听游戏";
            view.rightLabel.text = @"更多";
             view.moreImageView.image = [UIImage imageNamed:@"更多"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            [view addGestureRecognizer:tap];
            return view;
        }
            break;
        case 16:
            { HeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head16" forIndexPath:indexPath];

            view.frame = CGRectMake(0, 0, 0, 0);
            return view;
        }
            break;
        default:
            break;
    }
    return nil;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            
            return CGSizeMake(375 * FITWidth, 200 * FITHeight);
            break;
        case 1:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 2:
            
            return CGSizeMake(375 * FITWidth, 120 * FITHeight);
            break;
        case 3:
            
            return CGSizeMake(375 * FITWidth, 110 * FITHeight);
            break;
        case 4:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 5:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 6:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 7:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 8:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 9:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 10:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 11:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 12:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 13:
            
            
        case 14:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        case 15:
            
            return CGSizeMake(125 * FITWidth, 180 * FITHeight);
            break;
        default:
        case 16:
            
            return CGSizeMake(375 * FITWidth, 40 * FITHeight);
            break;
            
    }
    return CGSizeMake(0, 0);
}

#pragma mark -- 代理方法
-(void)sendMessage:(NSInteger )page{
//    for (NSString *str in [_focusDataSourceArray objectAtIndex:page]){
//        NSLog(@"%@", [[_focusDataSourceArray objectAtIndex:page] albumId]);
//    }

    S1mpl3Focus *s1mpl3Focus = [_focusDataSourceArray objectAtIndex:page];
    switch ([s1mpl3Focus.type integerValue]) {
        case 0:
            
            break;
        case 1:
            
            break;
        case 2:{
            S1mpl3AlbumViewController *s1mpl3AlbumVC = [[S1mpl3AlbumViewController alloc] init];
            s1mpl3AlbumVC.albumId = s1mpl3Focus.albumId;
            s1mpl3AlbumVC.myTitle = s1mpl3Focus.shortTitle;
            [self.s1mpl3Nav pushViewController:s1mpl3AlbumVC animated:YES];
        }
            
            break;
        case 3:{
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[LZPlayViewController shareInstance]];
            NSMutableArray *lzArray = [NSMutableArray arrayWithObjects:s1mpl3Focus, nil];
            NSMutableArray *array = [NSMutableArray array];
            [LZPlayViewController shareInstance].dataArray = lzArray;
            [TwoToOne getDataByString:[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/track/detail?device=android&trackId=%@", s1mpl3Focus.trackId] BodyString:nil WithDataBlock:^(id data) {
                [array addObject:data];
                [LZPlayViewController shareInstance].dicArray = array;
                [LZPlayViewController shareInstance].index = 0;
                [LZPlayViewController shareInstance].dic = data;
                [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"cell0"];
                [self.s1mpl3Nav presentViewController:nav animated:YES completion:nil];
            }];
        }
            
            break;
        case 4:{
            S1mpl3WebViewViewController *s1mpl3WebViewVC = [[S1mpl3WebViewViewController alloc] init];
            s1mpl3WebViewVC.urlString = s1mpl3Focus.url;
            [_s1mpl3Nav pushViewController:s1mpl3WebViewVC animated:YES];
        }
            
            break;
        case 5:
            
            break;
        case 6:
            
            break;
        case 7:
            
            break;
        case 8:
            
            break;
        case 9:
            
            break;
        case 10:{
            S1mpl3WebViewViewController *s1mpl3WebViewVC = [[S1mpl3WebViewViewController alloc] init];
            s1mpl3WebViewVC.urlString = s1mpl3Focus.url;
            [_s1mpl3Nav pushViewController:s1mpl3WebViewVC animated:YES];
        }
            
            break;
        default:
            break;
    }
    
}


#pragma mark --数据解析
-(void)getData{
    [_recommendCollectionView reloadData];
    _discoveryDataSourceArray = [NSMutableArray array];
    _recommendDataSourceArray = [NSMutableArray array];
    _focusDataSourceArray = [NSMutableArray array];
    _specialDataSourceArray = [NSMutableArray array];
    _hotRecommendDataSourceDictionary = [NSMutableDictionary dictionary];
    _hotRecommendListenDic = [NSMutableDictionary dictionary];
    [TwoToOne getDataByString:@"http://mobile.ximalaya.com/mobile/discovery/v1/recommends?channel=and-c57&device=android&includeActivity=true&includeSpecial=true&scale=2&version=4.3.20.2" BodyString:nil WithDataBlock:^(id data) {
        
        for (NSDictionary *dic in [[data objectForKey:@"discoveryColumns"] objectForKey:@"list"]) {
            Discovery *discovery = [[Discovery alloc] init];
            [discovery setValuesForKeysWithDictionary:dic];
            [_discoveryDataSourceArray addObject:discovery];
        }
        
        for (NSDictionary *dic in [[data objectForKey:@"editorRecommendAlbums"] objectForKey:@"list"]) {
            S1mpl3Recommend *recommend = [[S1mpl3Recommend alloc] init];
            [recommend setValuesForKeysWithDictionary:dic];
            [_recommendDataSourceArray addObject:recommend];
        }
        
        
        
        for (NSDictionary *dic in [[data objectForKey:@"focusImages"] objectForKey:@"list"]) {
            S1mpl3Focus *focus = [[S1mpl3Focus alloc] init];
            [focus setValuesForKeysWithDictionary:dic];
            [_focusDataSourceArray addObject:focus];
        }
        
        
        
        
        _hotRecommendArray = [NSMutableArray array];
        for (NSDictionary *dic in [[data objectForKey:@"hotRecommends"] objectForKey:@"list"]) {
          
            
            NSMutableArray *array = [NSMutableArray array];
            for (NSDictionary *subDic in [dic objectForKey:@"list"]) {
                S1mpl3Recommend *hotRecommend = [[S1mpl3Recommend alloc] init];
                [hotRecommend setValuesForKeysWithDictionary:subDic];
                [array addObject:hotRecommend];
            }
            
            [_hotRecommendArray addObject:[dic objectForKey:@"title"]];
            [_hotRecommendDataSourceDictionary setValue:array forKey:[dic objectForKey:@"title"]];
            [_hotRecommendListenDic setValue:[dic objectForKey:@"categoryId"] forKey:[dic objectForKey:@"title"]];
            
            //NSDictionary *hotRecommendDic = [NSDictionary dictionaryWithObject:array forKey:[dic objectForKey:@"title"]];
            //            [_hotRecommendDataSourceArray addObject:hotRecommendDic];
        }
        _titleArray = [_hotRecommendListenDic allKeys];
        for (NSDictionary *dic in [[data objectForKey:@"specialColumn"] objectForKey:@"list"]) {
            S1mpl3Special *special = [[S1mpl3Special alloc] init];
            [special setValuesForKeysWithDictionary:dic];
            [_specialDataSourceArray addObject:special];
        }
        [_recommendCollectionView reloadData];
        [_progressView removeFromSuperview];
    }];
    
}
@end
